<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a="http://richfaces.org/a4j"
                template="layout/template.xhtml">

    <ui:define name="body">

        <h:messages globalOnly="true" styleClass="message"/>

        <a:outputPanel ajaxRendered="true">
            <h:form id="positionForm">

                <rich:panel>
                    <f:facet name="header">position</f:facet>

                    <s:decorate id="traitDecoration" template="layout/edit.xhtml">
                        <ui:define name="label">Trait</ui:define>
                        <h:selectOneMenu id="trait"
                                         value="#{positionHome.instance.trait}"
                                         required="true">
                            <a:support event="onchange" reRender="detailsField" />
                            <s:selectItems var="_traitList" value="#{traitList}"
                                           noSelectionLabel="-- Select --"
                                           label="#{_traitList.name}"/>

                            <s:convertEntity/>
                        </h:selectOneMenu>
                    </s:decorate>
                    <s:decorate id="resultDecoration" template="layout/edit.xhtml">
                        <ui:define name="label">Result</ui:define>
                        <h:selectOneMenu id="result"
                                         value="#{positionHome.instance.result}"
                                         required="true">
                            <s:selectItems var="_resList" value="#{resultList}"
                                           label="#{_resList.description}"/>
                            <s:convertEntity/>
                        </h:selectOneMenu>
                    </s:decorate>

                    <div style="clear:both"/>

                </rich:panel>
                <rich:panel id="detailsField" rendered="#{not empty positionHome.instance.trait}">
                    <f:facet name="header">Trait details</f:facet>
                    <rich:dataTable var="trait" value="#{positionHome.instance.trait}">
                        <rich:column>
                            <f:facet name="header">Name</f:facet>
                            #{trait.name}
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">Fails expectations</f:facet>
                            #{trait.failsExpectations}
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">Meets expectations</f:facet>
                            #{trait.meetsExpectations}
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">Exceeds expectations</f:facet>
                            #{trait.exceedsExpectations}
                        </rich:column>
                    </rich:dataTable>
                </rich:panel>

                <div class="actionButtons">
                    <h:commandButton id="save"
                                     value="Save"
                                     action="#{positionHome.persist}"
                                     rendered="#{!positionHome.managed}"/>
                    <h:commandButton id="update"
                                     value="Save"
                                     action="#{positionHome.update}"
                                     rendered="#{positionHome.managed}"/>
                    <h:commandButton id="delete"
                                     value="Delete"
                                     action="#{positionHome.remove}"
                                     immediate="true"
                                     rendered="#{positionHome.managed}"/>
                    <s:button propagation="end"
                              id="done"
                              value="Done"
                              view="/positionList.xhtml"/>
                </div>

            </h:form>
        </a:outputPanel>
    </ui:define>

</ui:composition>

